import * as JsEncrypt from 'jsencrypt/bin/jsencrypt'
import Cookies from 'js-cookie'
import config from '@/conf'

export default {
  setCookie (key, value) {
    Cookies.set(key, value, { expires: config.cookieExpires })
  },
  getCookie (key) {
    const cookie = Cookies.get(key)
    if (cookie) return cookie
    else return false
  },
  delCookie (key) {
    Cookies.remove(key)
  },
  JSEncrypt (str) {
    let jse = new JsEncrypt.JSEncrypt()
    jse.setPublicKey(`-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpHVZ5aUsK2/ivkUhVxDcLLu+M
K6taVckc0yKnF+tDZ9D1P1nyi8B/OE+wgUjWT6VQYMfQFW/Xp6Ro1W5mc4uLDq7N
cZh2NEdCkQHKMA+0leEKgB4std3JwWMPxLxbdDPw/lKFkZuNUCTtq6UGLG01Ml4y
rNKT8/nekssUHnj0YwIDAQAB
-----END PUBLIC KEY-----`)
    let encrypted = jse.encrypt(str)
    return encrypted
  },
  JSDecrypt (str) {
    let jse = new JsEncrypt.JSEncrypt()
    jse.setPrivateKey(`-----BEGIN PRIVATE KEY-----
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAKkdVnlpSwrb+K+R
SFXENwsu74wrq1pVyRzTIqcX60Nn0PU/WfKLwH84T7CBSNZPpVBgx9AVb9enpGjV
bmZzi4sOrs1xmHY0R0KRAcowD7SV4QqAHiy13cnBYw/EvFt0M/D+UoWRm41QJO2r
pQYsbTUyXjKs0pPz+d6SyxQeePRjAgMBAAECgYBmG7Kkp/CJY/upddzo/AoIFJTK
W2ugpX9CijC4FvcTwdEm4tNaYQsfRU7IUac6zugPuf+rIeZfnXblXUjFTyqHFlRB
c7qta+FKUwHwi/qSlCNrvAtHYFd6wSdlU5qBnczu05Z0fxCFqi1B0J86Po6r5d0t
zo6G3xJQTfXk4W70kQJBANK3iyB39jhBJlX8sbGGcgKgm8Q/kdGoWuhwSF+/Vj+t
uAsuPcpS8uI9kPtYXTAmbixoKEbmtkOSyVc49FPoNL0CQQDNdRE53+M5Rd9w1PcS
uGthaQlIKV7ycvoombdKsnu2XVSzZTvt6cSUkp+9Zmc+SSsQna6Bon333t07A1yY
r6+fAkEAl7rwpK2dD37iMvKlpVZRTFEIOPUpdBXNeCg6BTAK1AmsR+jBN6opGP4K
IuLLH3vcw38w2XUR83CEKJlrXewL5QJBAKAKctKsLaltXjHcEmHIugx070AAye79
1RNPOdG72lYhuVrMnrQihnhdBoVYgU+pWxxkV4yvcIRmW9oeMkDViW0CQQDARREq
UMbsZSJovkPLlhZIJ0vgxy9yLAb6XkdO5WF1T5q3tRxbLI3cKnyg09RTZa7YOmQC
dqW2yL1rNfMXGrEo
-----END PRIVATE KEY-----`)
    let decrypted = jse.decrypt(str)
    return decrypted
  }
}
